package com.stella.ieproductivitybackend.controller;

import com.stella.ieproductivitybackend.entity.*;
import com.stella.ieproductivitybackend.entity.Progress;
import com.stella.ieproductivitybackend.service.FactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 工厂页控制层
 */
@RestController
@RequestMapping("/factory")
public class FactoryController {
    @Autowired
    private FactoryService factoryService;

    /**
     * 工厂列表
     */
    @PostMapping("/getFactoryList")
    public List<Factory> getFactoryList() {
        return factoryService.getFactoryList();
    }

    /**
     * 品牌列表
     */
    @PostMapping("/getBrandList")
    public List<Brand> getBrandList(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getBrandList(factory);
    }

    /**
     * 型体数量
     */
    @PostMapping("/getModelCount")
    public Integer getModelCount(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getModelCount(factory);
    }

    /**
     * 型体列表
     */
    @PostMapping("/getModelList")
    public List<Model> getModelList(@RequestBody Map<String, String> params) {
        String factory = params.get("factory") != null ? params.get("factory") : "";
        return factoryService.getModelList(factory);
    }

    /**
     * 搜索型体
     */
    @PostMapping("/searchModel")
    public List<Model> searchModel(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return factoryService.searchModel(factory, model);
    }

    /**
     * 员工总数
     */
    @PostMapping("/getEmployeeCount")
    public int getEmployeeCount(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getEmployeeCount(factory);
    }

    /**
     * 直间人工力其他数据
     */
    @PostMapping("/getEmployeeOther")
    public Map<String, Object> getEmployeeOther() {
        return factoryService.getEmployeeOther();
    }

    /**
     * 直间人工力详情
     */
    @PostMapping("/getEmployeeDetail")
    public List<Employee> getEmployeeDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        return factoryService.getEmployeeDetail(factory, year);
    }

    /**
     * 纯粹达成率图表
     */
    @PostMapping("/getPureChart")
    public Map<String, Object> getPureChart(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getPureChart(factory);
    }

    /**
     * 纯粹达成率详情
     */
    @PostMapping("/getPureDetail")
    public Map<String, List<Pure>> getPureDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getPureDetail(factory);
    }

    /**
     * 直间达成率图表
     */
    @PostMapping("/getDirectChart")
    public Map<String, Object> getDirectChart(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getDirectChart(factory);
    }

    /**
     * 直间达成率详情
     */
    @PostMapping("/getDirectDetail")
    public Map<String, List<Direct>> getDirectDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getDirectDetail(factory);
    }

    /**
     * 入库标准秒值图表
     */
    @PostMapping("/getWarehousingChart")
    public Map<String, Object> getWarehousingChart(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getWarehousingChart(factory);
    }

    /**
     * 入库标准秒值其他数据
     */
    @PostMapping("/getWarehousingOther")
    public Map<String, Object> getWarehousingOther(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getWarehousingOther(factory);
    }

    /**
     * 入库标准秒值详情
     */
    @PostMapping("/getWarehousingDetail")
    public List<Warehousing> getWarehousingDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        return factoryService.getWarehousingDetail(factory, year);
    }

    /**
     * 入库标准秒值对比
     */
    @PostMapping("/getWarehousingCompare")
    public List<Warehousing> getWarehousingCompare(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year1 = params.get("year1") != null ? params.get("year1").toString() : "";
        String month1 = params.get("month1") != null ? params.get("month1").toString() : "";
        String year2 = params.get("year2") != null ? params.get("year2").toString() : "";
        String month2 = params.get("month2") != null ? params.get("month2").toString() : "";
        return factoryService.getWarehousingCompare(factory, year1, month1, year2, month2);
    }

    /**
     * 当月成型完工数量图表
     */
    @PostMapping("/getCompletedChart")
    public CompletedChart getCompletedChart(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getCompletedChart(factory);
    }

    /**
     * 成型完工数量其它
     */
    @PostMapping("/getCompletedOther")
    public Map<String, Object> getCompletedOther(@RequestBody Map<String, String> params) {
        String factory = params.get("factory") != null ? params.get("factory") : "";
        return factoryService.getCompletedOther(factory);
    }

    /**
     * 成型完工数量详情
     */
    @PostMapping("/getCompletedDetail")
    public List<Completed> getCompletedDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        return factoryService.getCompletedDetail(factory, year);
    }

    /**
     * 当月新旧型体占比图表
     */
    @PostMapping("/getProportionChart")
    public ProportionChart getProportionChart(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getProportionChart(factory);
    }

    /**
     * 新旧型体占比其它
     */
    @PostMapping("/getProportionOther")
    public Map<String, Object> getProportionOther(@RequestBody Map<String, String> params) {
        String factory = params.get("factory") != null ? params.get("factory") : "";
        return factoryService.getProportionOther(factory);
    }

    /**
     * 新旧型体占比详情
     */
    @PostMapping("/getProportionDetail")
    public List<Proportion> getProportionDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        return factoryService.getProportionDetail(factory, year);
    }

    /**
     * PPH 图表
     */
    @PostMapping("/getPPHChart")
    public Map<String, Object> getPPHChart(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getPPHChart(factory);
    }

    /**
     * PPH 详情
     */
    @PostMapping("/getPPHDetail")
    public Map<String, List<PPH>> getPPHDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getPPHDetail(factory);
    }

    /**
     * 与核算进度达成图表
     */
    @PostMapping("/getProgressChart")
    public Map<String, Object> getProgressChart(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        return factoryService.getProgressChart(factory);
    }

    /**
     * 与核算进度达成其它
     */
    @PostMapping("/getProgressOther")
    public Map<String, Object> getProgressOther(@RequestBody Map<String, String> params) {
        String factory = params.get("factory") != null ? params.get("factory") : "";
        return factoryService.getProgressOther(factory);
    }

    /**
     * 与核算进度达成详情
     */
    @PostMapping("/getProgressDetail")
    public List<Progress> getProgressDetail(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String year = params.get("year") != null ? params.get("year").toString() : "";
        String month = params.get("month") != null ? params.get("month").toString() : "";
        return factoryService.getProgressDetail(factory, year, month);
    }

    /**
     * 型体工时效率
     */
    @PostMapping("/getEfficiency")
    public List<Efficiency> getEfficiency(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String startTime = params.get("startTime") != null ? params.get("startTime").toString() : "";
        String endTime = params.get("endTime") != null ? params.get("endTime").toString() : "";
        List<String> brand = params.get("brand") != null ? (List<String>) params.get("brand") : new ArrayList<>();
        String model = params.get("model") != null ? params.get("model").toString() : "";
        return factoryService.getEfficiency(factory, startTime, endTime, brand, model);
    }

    /**
     * 制程组别纯粹达成率及排名
     */
    @PostMapping("/getRanking")
    public List<Ranking> getRanking(@RequestBody Map<String, Object> params) {
        String factory = params.get("factory") != null ? params.get("factory").toString() : "";
        String thisTime = params.get("thisTime") != null ? params.get("thisTime").toString() : "";
        String lastTime = params.get("lastTime") != null ? params.get("lastTime").toString() : "";
        String operation = params.get("operation") != null ? params.get("operation").toString() : "";
        return factoryService.getRanking(factory, thisTime, lastTime, operation);
    }
}
